package org.skipper.samples.nacos.server.controller;

import lombok.extern.log4j.Log4j2;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.skipper.common.result.Result;
import org.skipper.common.result.RpcResult;
import org.skipper.samples.client.DemoService;
import org.skipper.samples.dto.DemoDTO;
import org.skipper.spring.cloud.annotation.IsLogin;
import org.skipper.spring.cloud.annotation.IsSign;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author shoujian
 * Date: 2022-01-12
 * Time: 11:02 AM
 */
@Log4j2
@RestController
@RequestMapping("/voyage")
public class VoyageController {

    @DubboReference(version = "1.0.0", group = "voyage-samples-dubbo-consumer")
    DemoService demoService;

    @GetMapping(value = "message")
    public Result<DemoDTO> getMessage() {
        RpcResult<DemoDTO> rpcResult = demoService.sayHello();
        DemoDTO demoDTO = rpcResult.getData();
        return Result.createSuccessMsg(demoDTO);
    }

    @GetMapping(value = "messageNeedLogin")
    @IsLogin
    public Result<DemoDTO> getMessageNeedLogin() {
        RpcResult<DemoDTO> rpcResult = demoService.sayHello();

        return Result.createSuccessMsg(rpcResult.getData());
    }

    @GetMapping(value = "messageNeedSign")
    @IsSign
    public Result<DemoDTO> getMessageNeedSign() {
        RpcResult<DemoDTO> rpcResult = demoService.sayHello();

        return Result.createSuccessMsg(rpcResult.getData());
    }

}
